function getData(event,type,url){
	$.ajax({
		url:url,
		type:"post",
		dataType:"json",
		success:function (result) {
			if(result.code == 200){
				initEcharts(event,type,result.data);
			}else{
				layer.msg(result.msg);
			}
		}
	})
}


function initEcharts(event,type,data){
	var myChart = echarts.init(document.getElementById(event));
	var option = getOptions(type,data);

	myChart.setOption(option);
	$("div#"+event).css("width","auto");
	$(window).resize(function() {
		myChart.resize();
	});
}

function getOptions(type,data){
	var option = null;
	if(parseInt(type) == 1){
		option = {
			color: ['#1C9399', '#FFC15E','#FA675C'],
			title:{
				text:'总人数',
				subtext:data.allCount,
				textStyle:{
					fontSize:14,
				},

				subtextStyle:{
					fontSize:30,
					fontWeight: 'bold',
					color:'#333',
					lineHeight: 0
				},
				x: 'center',
				y: '120',
				itemGap: 27,
			},
			legend: {
				selectedMode: false, //取消图例上的点击事件
				orient: 'vertical',
				right: 10,
				bottom: 20,
				itemWidth: 8,
				itemHeight: 8,
				itemGap: 20, //图例之间的间距
				textStyle: {
					color: '#333',
					fontSize: 12,
					padding: [4, 0, 0, 10]
				},
				data: data.title,
				formatter: function(name) {
					var data1 = option.series[0].data;
					var total = data.allCount;
					var tarValue;
					for (var i = 0, l = data1.length; i < l; i++) {
						if (data1[i].name == name) {
							tarValue = data1[i].value;
							break;
						}
					}
					if(parseInt(total) > 0) {
						var p = (tarValue / total * 100).toFixed(0);
						return name + '：' + p + '%';
					}else{
						return name + '：0' + '%';
					}
				},
			},
			series: [{
				name: '',
				type: 'pie',
				radius: [100,70],
				//center: ['40%', 'center'],
				center: 'center',
				avoidLabelOverlap: false,
				hoverAnimation:false,   //  防止点击变大事件
				labelLine: {
					normal: {
						length: 45, // 改变标示线的长度
						length2: 15,
					},
				},
				itemStyle: {
					normal: {
						label: {
							show: true,
							formatter: "{c} 人",
							textStyle: {
								color: '#333'
							},
							padding: [0, 0], //文字和图的边距
							rich: {
								b: { //value 文字样式
									fontSize: 12,
									lineHeight: 60,
									align: 'center',
									color: '#333'
								},
							}
						},
						show: true,
					},
				},
				data: data.data,
			}],
		};
	}else if(parseInt(type) == 2){
		option = {
			grid: {
				top:'20',
				left: '0',   //图表距边框的距离
				right: '0',
				bottom: '0',
				containLabel: true
			},
			xAxis: {
				type: 'category',
				axisLabel: {
					textStyle: {
						color:'#333',
						fontSize: 12,
					}
				},
				axisTick:{
					show:false  //去掉y轴刻度线
				},

				//坐标轴颜色
				axisLine:{
					show:true,
					lineStyle: {
						color: 'rgba(0, 0, 0, 0.45)',
						width: '1'
					}
				},
				data: data.names
			},
			yAxis: [
				{
					type: 'value',
					min:0,
					max:data.max,
					splitNumber:5,
					splitLine: {
						show: true ,
						lineStyle: {
							color: 'rgba(0, 0, 0, 0.15)',
							width: '1'
						}
					},
					axisLabel: {
						textStyle: {
							color:'#333',
							fontSize: 12,
						},
					},

					axisTick:{
						show:false  //去掉y轴刻度线
					},
					//坐标轴颜色
					axisLine:{
						show:false,
					},
				}
			],
			series: [{
				name:'',
				type:'bar',
				barWidth: '50',
				itemStyle : {
					normal : {
						barBorderRadius:[2, 2, 0, 0],
						label: {
							show: true,//是否展示
							position: 'top',
							textStyle: {
								fontSize: 14,
								color:'#333',
							}
						},
						color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
							offset: 1,
							color: '#1C9399'
						}, {
							offset: 0.3,
							color: '#3CC5C9'
						}]),
					}
				},
				data: data.values
			},]
		};
	}else if(parseInt(type) == 3){
		option = {
			grid: {
				top:'20',
				left: '0',   //图表距边框的距离
				right: '0',
				bottom: '0',
				containLabel: true
			},
			xAxis: {
				type: 'category',
				axisLabel: {
					textStyle: {
						color:'#333',
						fontSize: 12,
					},
				},
				axisTick:{
					show:false  //去掉y轴刻度线
				},
				//坐标轴颜色
				axisLine:{
					show:true,
					lineStyle: {
						color: 'rgba(0, 0, 0, 0.45)',
						width: '1'
					}
				},
				data: data.names
			},
			yAxis: [
				{
					type: 'value',
					min:0,
					max:data.max,
					splitNumber:5,
					splitLine: {
						show: true ,
						lineStyle: {
							color: '#eee',
							width: '1'
						}
					},
					axisLabel: {
						textStyle: {
							color:'#333',
							fontSize: 12,
						},

					},

					axisTick:{
						show:false  //去掉y轴刻度线
					},
					//坐标轴颜色
					axisLine:{
						show:false,
					},
				}
			],
			series: [
				{
					name:'安亭片',
					type:'line',
					smooth: true,
					itemStyle : {
						normal : {
							barBorderRadius:[2, 2, 0, 0],
							label: {
								show: true,//是否展示
								position: 'top',
								textStyle: {
									fontSize: 12,
									color:'#1C9399',
								}
							},
							color: '#1C9399'
						},

					},
					data: data.values1
				},
				{
					name:'黄渡片',
					type:'line',
					smooth: true,
					itemStyle : {
						normal : {
							barBorderRadius:[2, 2, 0, 0],
							label: {
								show: true,//是否展示
								position: 'top',
								textStyle: {
									fontSize: 12,
									color:'#FA675C',
								}
							},
							color: '#FA675C'
						},

					},
					data: data.values2
				},
				{
					name:'方泰片',
					type:'line',
					smooth: true,
					itemStyle : {
						normal : {
							barBorderRadius:[2, 2, 0, 0],
							label: {
								show: true,//是否展示
								position: 'top',
								textStyle: {
									fontSize: 12,
									color:'#FFC15E',
								}
							},
							color: '#FFC15E'
						},

					},
					data: data.values3
				},]
		};
	}else if(parseInt(type) == 4){
		option = {
			grid: {
				top:'30',
				left: '0',   //图表距边框的距离
				right: '0',
				bottom: '0',
				containLabel: true
			},
			xAxis: {
				type: 'category',
				axisLabel: {
					textStyle: {
						color:'#333',
						fontSize: 12,
					},
				},
				axisTick:{
					show:false  //去掉y轴刻度线
				},

				axisLine:{
					show:true,
					lineStyle: {
						color: 'rgba(0, 0, 0, 0.45)',
						width: '1'
					}
				},
				data: data.names
			},
			yAxis: [
				{
					type: 'value',
					min:0,
					max:data.max,
					splitNumber:5,
					splitLine: {
						show: true ,
						lineStyle: {
							color: 'rgba(0, 0, 0, 0.15)',
							width: '1'
						}
					},
					axisLabel: {
						textStyle: {
							color:'#333',
							fontSize: 12,
						},

					},

					axisTick:{
						show:false  //去掉y轴刻度线
					},
					//坐标轴颜色
					axisLine:{
						show:false,
					},
				}
			],
			series: [{
				name:'',
				type:'bar',
				barWidth: '25',
				itemStyle : {
					normal : {
						barBorderRadius:[2, 2, 0, 0],
						label: {
							show: true,//是否展示
							position: 'top',
							textStyle: {
								fontSize: 14,
								color:'#333',
							}
						},
						color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
							offset: 1,
							color: '#1C9399'
						}, {
							offset: 0.3,
							color: '#3CC5C9'
						}]),
					}
				},
				data: data.values1
			},{
				name:'',
				type:'bar',
				barWidth: '25',
				itemStyle : {
					normal : {
						barBorderRadius:[2, 2, 0, 0],
						label: {
							show: true,//是否展示
							position: 'top',
							textStyle: {
								fontSize: 14,
								color:'#333',
							}
						},
						color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
							offset: 1,
							color: '#FA675C'
						}, {
							offset: 0.3,
							color: '#FDA095'
						}]),
					}
				},
				data: data.values2
			},{
				name:'',
				type:'bar',
				barWidth: '25',
				itemStyle : {
					normal : {
						barBorderRadius:[2, 2, 0, 0],
						label: {
							show: true,//是否展示
							position: 'top',
							textStyle: {
								fontSize: 14,
								color:'#333',
							}
						},
						color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
							offset: 1,
							color: '#FFC15E'
						}, {
							offset: 0.3,
							color: '#FFE297'
						}]),
					}
				},
				data: data.values3
			}]
		};
	}

	return option;
}
